package com.sunfeng.chap2.p13;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description:  首先 启动Test13_10 然后执行本测试    发现是可以读的  通过 Test13_6 -Test13_11 发现 共享锁是只读的 自己和
 * @Date : 2021/10/9  16:48
 */
public class Test13_11 {
    public static void main(String[] args) throws IOException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("d:\\nio\\a.txt", "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        fileChannel.read(byteBuffer);

        byteBuffer.flip();
        while (byteBuffer.hasRemaining()) {
            System.out.print((char) byteBuffer.get());
        }
    }
}
